<template>
<div class="content">
  <div class="page-content">
    <div class="page-content-top" v-if="user.authenticationStatus == 2||user.authenticationStatus == 4">
      <Step :step="['创建名片','实名认证','授权认证','认证审核']" :active="3"></Step>
    </div>
      <div>
        <el-alert
            title="审核未通过"
            type="error"
            description=""
            show-icon
            class="warning-text" v-if="info.remarks">
          <div style="color: #E6A23C">未通过原因：{{info.remarks}}</div>
        </el-alert>
        <el-alert
            title="发布警告"
            type="warning"
            description="提示：请确保提交材料的真实性，账号仅限本人或本公司使用，否则可能导致你的账号被锁定或承担相应违法违规后果！"
            show-icon
            class="warning-text" v-else>
        </el-alert>
      </div>
    <template v-if="user.authenticationStatus == 3">
      <el-alert
          title="提示"
          type="warning"
          description="资料审核中，暂不可修改。"
          show-icon
          class="warning-text">
      </el-alert>
    </template>
    <div class="info-block" v-loading="formLoading" >
      <div class="title">公司全称：{{info.comName}}</div>
      <div class="title">营业执照</div>
      <div class="upload-block" v-if="user.authenticationStatus == 2||user.authenticationStatus == 4">
        <el-popover
            placement="top"
            trigger="click">
          <img src="https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/company_auth/business_license_sl.png" alt="" width="550px"/>
          <div slot='reference' class="tool-item">点击查看示例图片</div>
        </el-popover>
          <UploadFile :imageUrl="form.upLicense?[form.upLicense]:[]" @uploadSuccess="logoUrlSuccess" :accept="['jpg','jpeg','png']" :autoUpload="true" ></UploadFile>
      </div>
      <div class="upload-block" v-else>
        <el-popover
            placement="right"
            trigger="click">
          <img src="https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/company_auth/business_license_sl.png" alt="" width="500px"/>
          <div slot='reference' class="tool-item">点击查看示例图片</div>
        </el-popover>
<!--        <img :src="userForm.upLicense" alt="" class="photo"/>-->
        <el-image
            class="photo"
            fit="cover"
            :src="userForm.upLicense"
            :preview-src-list="srcList">
        </el-image>
      </div>
      <div class="title">招聘委托书</div>
      <div class="upload-block" v-if="user.authenticationStatus == 2||user.authenticationStatus == 4">
        <a class="tool-item" href="https://yumen.mashangjiuye.com/api/file/91885/%E6%8B%9B%E8%81%98%E5%A7%94%E6%89%98%E4%B9%A6.docx">点击下载招聘委托书模板.docx</a>
        <UploadFile :imageUrl="form.upRecruit?[form.upRecruit]:[]" @uploadSuccess="logoUrlSuccess1" :accept="['jpg','jpeg','png']" :autoUpload="true" ></UploadFile>
      </div>
      <div class="upload-block" v-else>
        <a class="tool-item" href="https://yumen.mashangjiuye.com/api/file/91885/%E6%8B%9B%E8%81%98%E5%A7%94%E6%89%98%E4%B9%A6.docx">点击下载招聘委托书模板.docx</a>
<!--        <img :src="userForm.upRecruit" alt="" class="photo"/>-->
        <el-image
            class="photo"
            fit="cover"
            :src="userForm.upRecruit"
            :preview-src-list="srcList1">
        </el-image>
      </div>
      <div class="title">身份证照片</div>
      <div class="upload-block1" v-if="user.authenticationStatus == 2||user.authenticationStatus == 4">
        <UploadFile :imageUrl="form.idCardJust?[form.idCardJust]:['https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/company_auth/front.png']" @uploadSuccess="logoUrlSuccess2" :accept="['jpg','jpeg','png']" :autoUpload="true" ></UploadFile>
        <UploadFile :imageUrl="form.idCardBack?[form.idCardBack]:['https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/company_auth/opposite.png']" @uploadSuccess="logoUrlSuccess3" :accept="['jpg','jpeg','png']" :autoUpload="true" ></UploadFile>
      </div>
      <div class="upload-block1" v-else>
        <el-image
            class="photo"
            fit="cover"
            :src="userForm.idCardJust"
            :preview-src-list="srcList2">
        </el-image>
        <el-image
            class="photo"
            fit="cover"
            :src="userForm.idCardBack"
            :preview-src-list="srcList3">
        </el-image>
<!--        <img :src="userForm.idCardJust" alt="" class="photo"/>-->
<!--        <img :src="userForm.idCardBack" alt="" class="photo"/>-->
      </div>
    </div>
   <div class="btn-item">
     <div class="btn2 btn-block" @click="submit" v-if="user.authenticationStatus == 2||user.authenticationStatus == 4">提交</div>
   </div>
  </div>
</div>
</template>

<script>
import Step from "@/components/Step/Step";
import {validate} from "@/utils/validate";
import UploadFile from "@/components/Upload/UploadFile.vue";
import {addComTwo, getEnterpriseData,getComRecruitersByIdApi} from "@/api/enterprise";
import {mapGetters} from "vuex";
export default {
  name: "MyProfile",
  components: {UploadFile,Step},
  data(){
    return{
      srcList:[],
      srcList1:[],
      srcList2:[],
      srcList3:[],
      info:{
        comName: '阿克赛市汉华国际有限公司',
        remarks: '',
      },
      formLoading: false,
      form:{
        upLicense: '',
        upRecruit: '',
        idCardJust: '',
        idCardBack: '',
      },
      userForm: {
        upLicense: '',
        upRecruit: '',
        idCardJust: '',
        idCardBack: '',
      },
      rules: {
        upLicense: {
          name: '营业执照',
          required: true
        },
        upRecruit: {
          name: '招聘授权书',
          required: true
        },
        idCardJust: {
          name: '身份证人像面',
          required: true
        },
        idCardBack: {
          name: '身份证国徽面',
          required: true
        },
      },
    }
  },
  methods:{
    logoUrlSuccess(e) {
      this.form.upLicense = e.data
    },
    logoUrlSuccess1(e) {
      this.form.upRecruit = e.data
    },
    logoUrlSuccess2(e) {
      this.form.idCardJust = e.data
    },
    logoUrlSuccess3(e) {
      this.form.idCardBack = e.data
    },
    getDetail() {
      getEnterpriseData({}).then((res) => {
        this.info=res;
      }).finally(()=>{
        this.formLoading=false
      })
    },
    getComRecruitersById() {
      getComRecruitersByIdApi({}).then((res) => {
        this.userForm=res;
        this.srcList=this.userForm.upLicense.split();
        this.srcList1=this.userForm.upRecruit.split();
        this.srcList2=this.userForm.idCardJust.split();
        this.srcList3=this.userForm.idCardBack.split();
        console.log(this.srcList)
      }).finally(()=>{
        this.formLoading=false
      })
    },
    submit() {
        if (this.formLoading) {
          this.$message.warning('请等待加载完成');
          return;
        }
          if (validate(this.form, this.rules)) {
          const loading = this.$loading({text: '加载中'})
          addComTwo(this.form).then(() => {
            this.$message.success('保存成功');
            this.$store.dispatch('user/getUser').finally(() => {
              this.$router.push({path: '/enterprise/authorization/examine'})
            });
          }).finally(() => {
            loading.close()
          })
        }
    },
  },
  computed: {
    ...mapGetters(['user'])
  },
  mounted() {
    this.getDetail();
    if (this.user && (this.user.authenticationStatus == 3 || this.user.authenticationStatus == 9)) {
      this.getComRecruitersById()
    }
  }
}
</script>

<style  lang="scss">
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 220px;
  height: 140px;
  line-height: 140px;
  text-align: center;
  margin-bottom: 15px;
  background: #F5F6F8;
  border-radius: 8px;
  margin-right: 20px;
}
.avatar {
  width: 220px;
  height: 140px;
  display: block;
  border-radius: 8px;
  margin-right: 20px;
}
.avatar-uploader-icon{
  font-size: 45px;
}
.content{
  width: 100%;
  .page-content{
    width: 100%;
    background-color: #FFFFFF;
    border-radius: 5px;
    padding: 20px 20px 20px 20px;
    .el-alert{
      .el-alert__icon{
        color: #E6A23C !important;
      }
    }
    .el-alert__content{
      .el-alert__title{
        color: #E6A23C !important;
      }
    }
    .info-block{
      display: flex;
      flex-direction: column;
      padding: 20px;
      .title{
        font-size: 16px;
        margin-bottom: 15px;
      }
      .upload-block{
        display: flex;
        flex-direction: column;
        .tool-item{
          width: 220px;
          font-size: 14px;
          color: #FF7626;
          cursor: pointer;
          margin-bottom: 15px;
        }
        .photo{
          width: 220px;
          height: 140px;
          background: #F5F6F8;
          border-radius: 8px;
          display: flex;
          justify-content: center;
          align-items: center;
          margin-bottom: 15px;
        }
      }
      .upload-block1{
        display: flex;
        flex-direction: row;
        .tool-item{
          font-size: 14px;
          color: #FF7626;
          cursor: pointer;
          margin-bottom: 15px;
        }
        .photo{
          width: 220px;
          height: 140px;
          border-radius: 8px;
          margin-bottom: 15px;
          margin-right: 20px;
        }
      }
    }
    .btn-item{
      display: flex;
      justify-content: center;
      .btn-block{
        width: 150px;
        height: 45px;
      }
    }
  }
}
</style>
